<template>
	<div class="videoFrame">
		<vueVideoPlayerCom :src="video.video" />
		<div @click="toVideoDetail($event,video.id)" class="text-wrap">
			<div class="videoTopDiv">
				<div class="videoName ellipsis">{{video.title}}</div>
			</div>
			<!-- <div class="videoTitle"> {{ video.content ? video.content.replace(/<[^<>]+>/g, "") : '无'}} </div> -->
			<div class="videoTitle" v-html="video.content.replace(/<[^<>]+>/g, '')" v-if="video.content.replace(/<[^<>]+>/g, '')"></div>
			<div class="videoTitle" v-else>无</div>
			<div class="videoFooter">
				<div class="pvDiv">
					<img src="@/assets/image/videoFrame/playIcon.png" style="margin-right: 5px"></img>
					<div v-if="video.pv > 10000"> {{ (video.pv / 10000).toFixed(2) + '万' }} </div>
					<div v-else>{{ video.pv }}</div>
				</div>
        <Buttons :buttons="buttons" @toSignUp="toSignUp(video.id)" @none="''"></Buttons>
			</div>
		</div>
	</div>
</template>

<script>
	// api
	import { uploadFile } from '@/utils/request.js'
	import config from '@/utils/config.js'
	// 引用视频插件
	import vueVideoPlayerCom from '@/components/vueVideoPlayerCom';
	export default {
		name: "videoFrame",
		props: {
			video: {
				type: Object,
				default: {}
			},
			url: {
				type: String,
				default: ''
			},
			showBtn: {
				type: Boolean,
				default: true
			}
		},
		components: { vueVideoPlayerCom },
    computed:{
      buttons(){
        if(this.video.isApply == 1){
          return [{text:"已参与",type:"normal-hover",size:"s",method:"none"}]
        }else {
          return [{text:"我要学习",type:"normal-hover",size:"s",method:"toSignUp"}]
        }
      }
    },
		data() {
			return {}
		},
		methods: {
			// 跳转在线课程详情页
			toVideoDetail($event,id) {
        if($event.target.nodeName == 'DIV'){
				  this.$router.push({ name: this.url, query: { id } }).catch(err => err);
        }
			},
			// 点击立即参与按钮
			toSignUp(id) {
				this.$CheckRole("线上课程报名", async () => {
					let formData = new FormData();
					formData.append('id', id);
					const { code, msg } = await uploadFile(this, config.api.joinOnlineCourse, formData, 'POST');
					if (code != '200') return this.$message.warning(msg);
					this.video.isApply = 1 
					this.$message.success('申请报名成功，请您准时参加培训！');
				})
			},
		}
	}
</script>

<style scoped>
	.videoFrame {
		box-shadow: 2px 4px 5px 1px rgba(0,19,39,0.06); 
	}

	.videoFrame .text-wrap{
		padding: 18px 12px;
		cursor: pointer;
	}

	.videoFrame .videoBox{
		width: 100%;
		text-align: center;
		border-radius: 4px;
		overflow: hidden;
		position: relative;
		box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
		margin-right: 4px;
	}

	.videoFrame .videoTopDiv {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* margin-top: 15px; */
	}

	.videoFrame .videoTopDiv .videoName {
		font-size: 18px;
		font-weight: bold;
		color: #333;
	}

	.pvDiv {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 12px;
	}

	.videoFrame .videoTitle {
		text-align: left;
		font-size: 14px;
		color: #999;
		margin-top: 5px;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}
	
	.videoFrame .videoFooter {
		margin-top: 10px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.videoFrame .videoFooter .videoWay {
		font-size: 12px;
		color: #333333;
	}

	.videoFrame .videoFooter .videoBtn {
		font-size: 14px;
		background-color: #f1f2f4;
		color: #045db9;
		padding: 5px 10px;
		border-radius: 5px;
		transition: all 0.2s ease 0s;
	}

	.videoFrame .videoFooter .videoBtn:hover {
		background-color: #045db9;
		color: #f1f2f4;
		cursor: pointer;
	}

</style>